<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>gozerlib.plugs.user &mdash; GOZERWAVE v0.1 BETA documentation</title>
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.1 BETA',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="top" title="GOZERWAVE v0.1 BETA documentation" href="../../index.html" />
    <link rel="next" title="gozerlib.plugs.userstate" href="userstate.html" />
    <link rel="prev" title="gozerlib.plugs.uniq" href="uniq.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="userstate.html" title="gozerlib.plugs.userstate"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="uniq.html" title="gozerlib.plugs.uniq"
             accesskey="P">previous</a> |</li>
        <li><a href="../../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-gozerlib.plugs.user">
<h1>gozerlib.plugs.user<a class="headerlink" href="#module-gozerlib.plugs.user" title="Permalink to this headline">¶</a></h1>
<p>users related commands.</p>
<dl class="function">
<dt id="gozerlib.plugs.user.handle_addperm">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_addperm</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_addperm" title="Permalink to this definition">¶</a></dt>
<dd>user-addperm &lt;name&gt; &lt;perm&gt; .. add permission.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_addpermall">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_addpermall</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_addpermall" title="Permalink to this definition">¶</a></dt>
<dd>user-addpermall &lt;perm&gt; .. add permission to all users.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_addpermit">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_addpermit</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_addpermit" title="Permalink to this definition">¶</a></dt>
<dd>user-addpermit &lt;name&gt; &lt;permit&gt; .. add permit to permit list of &lt;name&gt;.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_addstatus">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_addstatus</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_addstatus" title="Permalink to this definition">¶</a></dt>
<dd>user-addstatus &lt;name&gt; &lt;status&gt; .. add status of name.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_adduser">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_adduser</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_adduser" title="Permalink to this definition">¶</a></dt>
<dd>user-add &lt;name&gt; &lt;userhost&gt; .. introduce a new user to the bot.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_adduserhost">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_adduserhost</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_adduserhost" title="Permalink to this definition">¶</a></dt>
<dd>user-adduserhost &lt;name&gt; &lt;userhost&gt; .. add to userhosts of name.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_check">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_check</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_check" title="Permalink to this definition">¶</a></dt>
<dd>user-check &lt;nick&gt; .. get user data of &lt;nick&gt;.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_delemail">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_delemail</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_delemail" title="Permalink to this definition">¶</a></dt>
<dd>user-delemail .. reset email of user giving the command.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_delete">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_delete</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_delete" title="Permalink to this definition">¶</a></dt>
<dd>user-del &lt;name&gt; .. remove user.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_delperm">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_delperm</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_delperm" title="Permalink to this definition">¶</a></dt>
<dd>user-delperm &lt;name&gt; &lt;perm&gt; .. delete permission of name.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_delpermall">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_delpermall</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_delpermall" title="Permalink to this definition">¶</a></dt>
<dd>user-delpermall &lt;perm&gt; .. delete permission from all users.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_delstatus">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_delstatus</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_delstatus" title="Permalink to this definition">¶</a></dt>
<dd>user-delstatus &lt;name&gt; &lt;status&gt; .. delete status of name.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_deluserhost">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_deluserhost</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_deluserhost" title="Permalink to this definition">¶</a></dt>
<dd>user-deluserhost &lt;name&gt; &lt;userhost&gt; .. remove from userhosts of name.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_email">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_email</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_email" title="Permalink to this definition">¶</a></dt>
<dd>user-email .. show email of user giving the command.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_getemail">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_getemail</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_getemail" title="Permalink to this definition">¶</a></dt>
<dd>user-getemail &lt;name&gt; .. get email of name.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_getname">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_getname</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_getname" title="Permalink to this definition">¶</a></dt>
<dd>user-getname &lt;nick&gt; .. fetch name of nick.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_getperms">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_getperms</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_getperms" title="Permalink to this definition">¶</a></dt>
<dd>user-getperms &lt;name&gt; .. get permissions of name.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_getstatus">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_getstatus</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_getstatus" title="Permalink to this definition">¶</a></dt>
<dd>user-getstatus &lt;name&gt; .. get status of name.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_getuserhosts">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_getuserhosts</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_getuserhosts" title="Permalink to this definition">¶</a></dt>
<dd>user-getuserhosts &lt;name&gt; .. get userhosts of name.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_getuserperm">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_getuserperm</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_getuserperm" title="Permalink to this definition">¶</a></dt>
<dd>user-allperm &lt;perm&gt; .. list users with permission &lt;perm&gt;.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_getuserstatus">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_getuserstatus</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_getuserstatus" title="Permalink to this definition">¶</a></dt>
<dd>user-allstatus &lt;status&gt; .. list users with status &lt;status&gt;.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_import">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_import</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_import" title="Permalink to this definition">¶</a></dt>
<dd>user-import &lt;userhost&gt; .. merge the userhost into user giving the command.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_match">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_match</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_match" title="Permalink to this definition">¶</a></dt>
<dd>user-match &lt;userhost&gt; .. get data of &lt;userhost&gt;.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_meet">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_meet</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_meet" title="Permalink to this definition">¶</a></dt>
<dd>user-meet &lt;nick&gt; .. introduce a new user to the bot.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_merge">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_merge</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_merge" title="Permalink to this definition">¶</a></dt>
<dd>user-merge &lt;name&gt; &lt;nick&gt; .. merge the userhost into a already existing user.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_name">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_name</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_name" title="Permalink to this definition">¶</a></dt>
<dd>user-name .. show name of user giving the command.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_names">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_names</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_names" title="Permalink to this definition">¶</a></dt>
<dd>user-names .. show registered users.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_permit">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_permit</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_permit" title="Permalink to this definition">¶</a></dt>
<dd>user-permit .. get permit list of user giving the command.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_perms">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_perms</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_perms" title="Permalink to this definition">¶</a></dt>
<dd>user-perms .. get permission of the user given the command.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_setemail">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_setemail</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_setemail" title="Permalink to this definition">¶</a></dt>
<dd>user-setemail &lt;name&gt; .. set email of name.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_show">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_show</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_show" title="Permalink to this definition">¶</a></dt>
<dd>user-show &lt;name&gt; .. get data of &lt;name&gt;.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_status">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_status</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_status" title="Permalink to this definition">¶</a></dt>
<dd>user-status .. get status of user given the command.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_userdelpermit">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_userdelpermit</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_userdelpermit" title="Permalink to this definition">¶</a></dt>
<dd>user-delpermit &lt;name&gt; &lt;permit&gt; .. remove (name, permit) from permit list.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_userhosts">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_userhosts</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_userhosts" title="Permalink to this definition">¶</a></dt>
<dd>user-userhosts .. get userhosts of user giving the command.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_userscan">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_userscan</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_userscan" title="Permalink to this definition">¶</a></dt>
<dd>user-scan &lt;txt&gt; .. scan for user.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_usersearch">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_usersearch</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_usersearch" title="Permalink to this definition">¶</a></dt>
<dd>search for user matching given userhost.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.user.handle_whoami">
<tt class="descclassname">gozerlib.plugs.user.</tt><tt class="descname">handle_whoami</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.user.handle_whoami" title="Permalink to this definition">¶</a></dt>
<dd>user-whoami .. get your username.</dd></dl>

<div class="section" id="code">
<h2>code<a class="headerlink" href="#code" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><pre>  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974</pre></td><td class="code"><div class="highlight"><pre><span class="c"># plugs/user.py</span>
<span class="c">#</span>
<span class="c">#</span>

<span class="sd">&quot;&quot;&quot; users related commands. &quot;&quot;&quot;</span>

<span class="c">## gozerlib imports</span>

<span class="kn">from</span> <span class="nn">gozerlib.utils.generic</span> <span class="kn">import</span> <span class="n">getwho</span>
<span class="kn">from</span> <span class="nn">gozerlib.utils.exception</span> <span class="kn">import</span> <span class="n">handle_exception</span>
<span class="kn">from</span> <span class="nn">gozerlib.utils.name</span> <span class="kn">import</span> <span class="n">stripname</span>
<span class="kn">from</span> <span class="nn">gozerlib.users</span> <span class="kn">import</span> <span class="n">GozerUsers</span>
<span class="kn">from</span> <span class="nn">gozerlib.commands</span> <span class="kn">import</span> <span class="n">cmnds</span>
<span class="kn">from</span> <span class="nn">gozerlib.examples</span> <span class="kn">import</span> <span class="n">examples</span>
<span class="kn">from</span> <span class="nn">gozerlib.aliases</span> <span class="kn">import</span> <span class="n">aliasdel</span><span class="p">,</span> <span class="n">aliasset</span>

<span class="n">users</span> <span class="o">=</span> <span class="n">GozerUsers</span><span class="p">()</span>

<span class="k">def</span> <span class="nf">handle_whoami</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-whoami .. get your username. &quot;&quot;&quot;</span>

    <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">users</span><span class="o">.</span><span class="n">getname</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">auth</span><span class="p">))</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-whoami&#39;</span><span class="p">,</span> <span class="n">handle_whoami</span><span class="p">,</span> <span class="s">&#39;USER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-whoami&#39;</span><span class="p">,</span> <span class="s">&#39;get your username&#39;</span><span class="p">,</span> <span class="s">&#39;user-whoami&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;whoami&#39;</span><span class="p">,</span> <span class="s">&#39;user-whoami&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;whoami&#39;)</span>

<span class="k">def</span> <span class="nf">handle_meet</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-meet &lt;nick&gt; .. introduce a new user to the bot. &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">nick</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
    <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;nick&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="k">if</span> <span class="n">users</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">nick</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;there is already a user with username </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">nick</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">userhost</span> <span class="o">=</span> <span class="n">getwho</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">nick</span><span class="p">)</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">userhost</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t find userhost of </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">nick</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">username</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getname</span><span class="p">(</span><span class="n">userhost</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">username</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;we already have a user with userhost </span><span class="si">%s</span><span class="s"> (</span><span class="si">%s</span><span class="s">)&#39;</span> <span class="o">%</span> \
<span class="p">(</span><span class="n">userhost</span><span class="p">,</span> <span class="n">username</span><span class="p">))</span>
        <span class="k">return</span>

    <span class="n">result</span> <span class="o">=</span> <span class="mf">0</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">stripname</span><span class="p">(</span><span class="n">nick</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>
    <span class="n">result</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="p">[</span><span class="n">userhost</span><span class="p">,</span> <span class="p">],</span> <span class="p">[</span><span class="s">&#39;USER&#39;</span><span class="p">,</span> <span class="p">])</span>

    <span class="k">if</span> <span class="n">result</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> (</span><span class="si">%s</span><span class="s">) added to user database&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">nick</span><span class="p">,</span> <span class="n">name</span><span class="p">))</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;add failed&#39;</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-meet&#39;</span><span class="p">,</span> <span class="n">handle_meet</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;OPER&#39;</span><span class="p">,</span> <span class="s">&#39;MEET&#39;</span><span class="p">])</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-meet&#39;</span><span class="p">,</span> <span class="s">&#39;user-meet &lt;nick&gt; .. introduce &lt;nick&gt; to the </span><span class="se">\</span>
<span class="s">bot&#39;</span><span class="p">,</span> <span class="s">&#39;user-meet dunker&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;meet&#39;</span><span class="p">,</span> <span class="s">&#39;user-meet&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;meet test&#39;).add(&#39;delete test&#39;)</span>

<span class="k">def</span> <span class="nf">handle_adduser</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-add &lt;name&gt; &lt;userhost&gt; .. introduce a new user to the bot. &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">userhost</span><span class="p">)</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span>
    <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;name&gt; &lt;userhost&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">username</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getname</span><span class="p">(</span><span class="n">userhost</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">username</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;we already have a user with userhost </span><span class="si">%s</span><span class="s"> (</span><span class="si">%s</span><span class="s">)&#39;</span> <span class="o">%</span> \
<span class="p">(</span><span class="n">userhost</span><span class="p">,</span> <span class="n">username</span><span class="p">))</span>
        <span class="k">return</span>

    <span class="n">result</span> <span class="o">=</span> <span class="mf">0</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">stripname</span><span class="p">(</span><span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span> 
    <span class="n">result</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="p">[</span><span class="n">userhost</span><span class="p">,</span> <span class="p">],</span> <span class="p">[</span><span class="s">&#39;USER&#39;</span><span class="p">,</span> <span class="p">])</span>

    <span class="k">if</span> <span class="n">result</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> added to user database&#39;</span> <span class="o">%</span> <span class="n">name</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;add failed&#39;</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-add&#39;</span><span class="p">,</span> <span class="n">handle_adduser</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-add&#39;</span><span class="p">,</span> <span class="s">&#39;user-add &lt;name&gt; &lt;userhost&gt; .. add &lt;name&gt; with </span><span class="se">\</span>
<span class="s">&lt;userhost&gt; to the bot&#39;</span><span class="p">,</span> <span class="s">&#39;user-add dunker bart@localhost&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-add mtest1 mekker@test1&#39;, &#39;mtest1 added to user database&#39;).add(&#39;delete mtest1&#39;)</span>

<span class="k">def</span> <span class="nf">handle_merge</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-merge &lt;name&gt; &lt;nick&gt; .. merge the userhost into a already existing user. &quot;&quot;&quot;</span>

    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">)</span> <span class="o">!=</span> <span class="mf">2</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;name&gt; &lt;nick&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">name</span><span class="p">,</span> <span class="n">nick</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>

    <span class="k">if</span> <span class="n">users</span><span class="o">.</span><span class="n">gotperm</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">)</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">users</span><span class="o">.</span><span class="n">allowed</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">userhost</span><span class="p">,</span> \
<span class="s">&#39;OPER&#39;</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;only OPER perm can merge with OPER user&quot;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="k">if</span> <span class="n">name</span> <span class="o">==</span> <span class="s">&#39;owner&#39;</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">bot</span><span class="o">.</span><span class="n">ownercheck</span><span class="p">(</span><span class="n">ievent</span><span class="p">,</span> <span class="s">&quot;can merge with owner </span><span class="se">\</span>
<span class="s">user&quot;</span><span class="p">):</span>
         <span class="k">return</span> 

    <span class="k">if</span> <span class="ow">not</span> <span class="n">users</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;we have no user </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">name</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">userhost</span> <span class="o">=</span> <span class="n">getwho</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">nick</span><span class="p">)</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">userhost</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t find userhost of </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">nick</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="k">if</span> <span class="n">bot</span><span class="o">.</span><span class="n">ownercheck</span><span class="p">(</span><span class="n">userhost</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t merge with owner&quot;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">username</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getname</span><span class="p">(</span><span class="n">userhost</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">username</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;we already have a user with userhost </span><span class="si">%s</span><span class="s"> (</span><span class="si">%s</span><span class="s">)&#39;</span> <span class="o">%</span> \
<span class="p">(</span><span class="n">userhost</span><span class="p">,</span> <span class="n">username</span><span class="p">))</span>
        <span class="k">return</span>

    <span class="n">result</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">userhost</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">result</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> merged&#39;</span> <span class="o">%</span> <span class="n">nick</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;merge failed&#39;</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-merge&#39;</span><span class="p">,</span> <span class="n">handle_merge</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;OPER&#39;</span><span class="p">,</span> <span class="s">&#39;MEET&#39;</span><span class="p">])</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-merge&#39;</span><span class="p">,</span> <span class="s">&#39;user-merge &lt;name&gt; &lt;nick&gt; .. merge record with </span><span class="se">\</span>
<span class="s">&lt;name&gt; with userhost from &lt;nick&gt;&#39;</span><span class="p">,</span> <span class="s">&#39;merge bart dunker&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;merge&#39;</span><span class="p">,</span> <span class="s">&#39;user-merge&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-add mtest2 mekker@test2&#39;).add(&#39;merge mtest2 bottest&#39;, &#39;bottest merged&#39;).add(&#39;delete mtest2&#39;)</span>

<span class="k">def</span> <span class="nf">handle_import</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-import &lt;userhost&gt; .. merge the userhost into user giving the command. &quot;&quot;&quot;</span>

    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">)</span> <span class="o">!=</span> <span class="mf">1</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;userhost&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">userhost</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span>

    <span class="n">name</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getname</span><span class="p">(</span><span class="n">userhost</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">name</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;we already have a user with userhost </span><span class="si">%s</span><span class="s"> (</span><span class="si">%s</span><span class="s">)&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">userhost</span><span class="p">,</span> <span class="n">name</span><span class="p">))</span>
        <span class="k">return</span>

    <span class="k">if</span> <span class="n">bot</span><span class="o">.</span><span class="n">ownercheck</span><span class="p">(</span><span class="n">userhost</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t merge with owner&quot;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">result</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">userhost</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">result</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> imported&#39;</span> <span class="o">%</span> <span class="n">userhost</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;import failed&#39;</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-import&#39;</span><span class="p">,</span> <span class="n">handle_import</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;USER, &#39;</span><span class="p">])</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-import&#39;</span><span class="p">,</span> <span class="s">&#39;user-import &lt;userhost&gt; .. merge record with </span><span class="se">\</span>
<span class="s">&lt;name&gt; with userhost from the person giving the command (self merge)&#39;</span><span class="p">,</span> <span class="s">&#39;import bthate@gmail.com&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;merge&#39;</span><span class="p">,</span> <span class="s">&#39;user-merge&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-add mtest2 mekker@test2&#39;).add(&#39;merge mtest2 bottest&#39;, &#39;bottest merged&#39;).add(&#39;delete mtest2&#39;)</span>

<span class="k">def</span> <span class="nf">handle_delete</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-del &lt;name&gt; .. remove user. &quot;&quot;&quot;</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">bot</span><span class="o">.</span><span class="n">ownercheck</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">userhost</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;only owner can use delete&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mf">0</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;name&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">name</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
    <span class="n">result</span> <span class="o">=</span> <span class="mf">0</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">stripname</span><span class="p">(</span><span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
    <span class="n">result</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">result</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> deleted&#39;</span> <span class="o">%</span> <span class="n">name</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;delete of </span><span class="si">%s</span><span class="s"> failed&#39;</span> <span class="o">%</span> <span class="n">name</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-del&#39;</span><span class="p">,</span> <span class="n">handle_delete</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-del&#39;</span><span class="p">,</span> <span class="s">&#39;user-del &lt;name&gt; .. delete user with &lt;username&gt;&#39;</span> <span class="p">,</span> <span class="s">&#39;user-del dunker&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;delete&#39;</span><span class="p">,</span> <span class="s">&#39;user-del&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-add mtest3 mekker@test3&#39;).add(&#39;delete mtest3&#39;, &#39;mtest3 deleted&#39;)</span>

<span class="k">def</span> <span class="nf">handle_userscan</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-scan &lt;txt&gt; .. scan for user. &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">name</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span>
    <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;txt&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
    <span class="n">names</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">names</span><span class="p">()</span>

    <span class="n">result</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">names</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">i</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="n">name</span><span class="p">)</span> <span class="o">!=</span> <span class="o">-</span><span class="mf">1</span><span class="p">:</span>
            <span class="n">result</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">result</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;users matching </span><span class="si">%s</span><span class="s">: &quot;</span> <span class="o">%</span> <span class="n">name</span><span class="p">,</span> <span class="n">result</span><span class="p">,</span> <span class="n">dot</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;no users matched&#39;</span><span class="p">)</span>
        <span class="k">return</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-scan&#39;</span><span class="p">,</span> <span class="n">handle_userscan</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-scan&#39;</span><span class="p">,</span> <span class="s">&#39;user-scan &lt;txt&gt; .. search database for matching usernames&#39;</span><span class="p">,</span> <span class="s">&#39;user-scan dunk&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;us&#39;</span><span class="p">,</span> <span class="s">&#39;user-scan&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-add mtest4 mekker@test4&#39;).add(&#39;user-scan mte&#39;, &#39;mtest4&#39;).add(&#39;delete mtest4&#39;)</span>

<span class="k">def</span> <span class="nf">handle_names</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-names .. show registered users. &quot;&quot;&quot;</span>

    <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;usernames: &quot;</span><span class="p">,</span> <span class="n">users</span><span class="o">.</span><span class="n">names</span><span class="p">(),</span> <span class="n">dot</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-names&#39;</span><span class="p">,</span> <span class="n">handle_names</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-names&#39;</span><span class="p">,</span> <span class="s">&#39;show names of registered users&#39;</span><span class="p">,</span> <span class="s">&#39;user-names&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;names&#39;</span><span class="p">,</span> <span class="s">&#39;user-names&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-add mtest5 mekker@test&#39;).add(&#39;user-names&#39;, &#39;mtest5&#39;).add(&#39;delete mtest5&#39;)</span>

<span class="k">def</span> <span class="nf">handle_name</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-name .. show name of user giving the command. &quot;&quot;&quot;</span>

    <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;your name is </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">users</span><span class="o">.</span><span class="n">getname</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">userhost</span><span class="p">))</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-name&#39;</span><span class="p">,</span> <span class="n">handle_name</span><span class="p">,</span> <span class="s">&#39;USER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-name&#39;</span><span class="p">,</span> <span class="s">&#39;show name of user giving the commands&#39;</span><span class="p">,</span> <span class="s">&#39;user-name&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;name&#39;</span><span class="p">,</span> <span class="s">&#39;user-name&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-name&#39;, &#39;exec&#39;)</span>

<span class="k">def</span> <span class="nf">handle_getname</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-getname &lt;nick&gt; .. fetch name of nick. &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">nick</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span>
    <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&quot;&lt;nick&gt;&quot;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">userhost</span> <span class="o">=</span> <span class="n">getwho</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">nick</span><span class="p">)</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">userhost</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t find userhost of </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">nick</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">name</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getname</span><span class="p">(</span><span class="n">userhost</span><span class="p">)</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">name</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t find user for </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">userhost</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-getname&#39;</span><span class="p">,</span> <span class="n">handle_getname</span><span class="p">,</span> <span class="s">&#39;USER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-getname&#39;</span><span class="p">,</span> <span class="s">&#39;user-getname &lt;nick&gt; .. get the name of &lt;nick&gt;&#39;</span><span class="p">,</span> <span class="s">&#39;user-getname dunker&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;gn&#39;</span><span class="p">,</span> <span class="s">&#39;user-getname&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;getname&#39;</span><span class="p">,</span> <span class="s">&#39;user-getname&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-getname test&#39;)</span>

<span class="k">def</span> <span class="nf">handle_addperm</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-addperm &lt;name&gt; &lt;perm&gt; .. add permission. &quot;&quot;&quot;</span>

    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">)</span> <span class="o">!=</span> <span class="mf">2</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;name&gt; &lt;perm&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">name</span><span class="p">,</span> <span class="n">perm</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span>
    <span class="n">perm</span> <span class="o">=</span> <span class="n">perm</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">users</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t find user </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">name</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">result</span> <span class="o">=</span> <span class="mf">0</span>

    <span class="k">if</span> <span class="n">users</span><span class="o">.</span><span class="n">gotperm</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">perm</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> already has permission </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">perm</span><span class="p">))</span>
        <span class="k">return</span>         

    <span class="n">result</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">adduserperm</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">perm</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">result</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> perm added&#39;</span> <span class="o">%</span> <span class="n">perm</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;perm add failed&#39;</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-addperm&#39;</span><span class="p">,</span> <span class="n">handle_addperm</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-addperm&#39;</span><span class="p">,</span> <span class="s">&#39;user-addperm &lt;name&gt; &lt;perm&gt; .. add permissions to user &lt;name&gt;&#39;</span><span class="p">,</span> <span class="s">&#39;user-addperm dunker rss&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;setperms&#39;</span><span class="p">,</span> <span class="s">&#39;user-addperm&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;addperms&#39;</span><span class="p">,</span> <span class="s">&#39;user-addperm&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-add mtest6 mekker@test6&#39;, &#39;mtest6&#39;).add(&#39;user-addperm mtest6 mekker&#39;, &#39;MEKKER perm added&#39;).add(&#39;delete mtest6&#39;)</span>

<span class="k">def</span> <span class="nf">handle_getperms</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-getperms &lt;name&gt; .. get permissions of name. &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">name</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span>
    <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;name&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">users</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t find user </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">name</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">perms</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getuserperms</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">perms</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;permissions of </span><span class="si">%s</span><span class="s">: &quot;</span> <span class="o">%</span> <span class="n">name</span><span class="p">,</span> <span class="n">perms</span><span class="p">,</span> <span class="n">dot</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> has no permissions set&#39;</span> <span class="o">%</span> <span class="n">name</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-getperms&#39;</span><span class="p">,</span> <span class="n">handle_getperms</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-getperms&#39;</span><span class="p">,</span> <span class="s">&#39;user-getperms &lt;name&gt; .. get permissions of &lt;name&gt;&#39;</span><span class="p">,</span> <span class="s">&#39;user-getperms dunker&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;getperms&#39;</span><span class="p">,</span> <span class="s">&#39;user-getperms&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-add mtest7 mekker@test7&#39;).add(&#39;user-addperm mtest7 mekker&#39;).add(&#39;user-getperms mtest7&#39; , &#39;MEKKER&#39;).add(&#39;delete mtest7&#39;)</span>

<span class="k">def</span> <span class="nf">handle_perms</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-perms .. get permission of the user given the command. &quot;&quot;&quot;</span>

    <span class="k">if</span> <span class="n">ievent</span><span class="o">.</span><span class="n">rest</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;use getperms to get the permissions of somebody else&quot;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">name</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getname</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">userhost</span><span class="p">)</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">name</span><span class="p">:</span>
         <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t find username for </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">ievent</span><span class="o">.</span><span class="n">userhost</span><span class="p">)</span>
         <span class="k">return</span>

    <span class="n">perms</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getuserperms</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">perms</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;you have permissions: &quot;</span><span class="p">,</span> <span class="n">perms</span><span class="p">,</span> <span class="n">dot</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-perms&#39;</span><span class="p">,</span> <span class="n">handle_perms</span><span class="p">,</span> <span class="s">&#39;USER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-perms&#39;</span><span class="p">,</span> <span class="s">&#39;get permissions&#39;</span><span class="p">,</span> <span class="s">&#39;user-perms&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;perms&#39;</span><span class="p">,</span> <span class="s">&#39;user-perms&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-perms&#39;, &#39;USER&#39;)</span>

<span class="k">def</span> <span class="nf">handle_delperm</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-delperm &lt;name&gt; &lt;perm&gt; .. delete permission of name. &quot;&quot;&quot;</span>

    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">)</span> <span class="o">!=</span> <span class="mf">2</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;name&gt; &lt;perm&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">name</span><span class="p">,</span> <span class="n">perm</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span>
    <span class="n">perm</span> <span class="o">=</span> <span class="n">perm</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">users</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t find user </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">name</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">result</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">deluserperm</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">perm</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">result</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> perm removed&#39;</span> <span class="o">%</span> <span class="n">perm</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;</span><span class="si">%s</span><span class="s"> has no </span><span class="si">%s</span><span class="s"> permission&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">perm</span><span class="p">))</span>
        <span class="k">return</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-delperm&#39;</span><span class="p">,</span> <span class="n">handle_delperm</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-delperms&#39;</span><span class="p">,</span> <span class="s">&#39;delete from user &lt;name&gt; permission &lt;perm&gt;&#39;</span><span class="p">,</span> <span class="s">&#39;user-delperms dunker rss&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-add mtest8 mekker@test8&#39;).add(&#39;user-addperm mtest8mekker&#39;).add(&#39;user-delperm mtest8 mekker&#39;, &#39;MEKKER&#39;).add(&#39;delete mtest8&#39;)</span>

<span class="k">def</span> <span class="nf">handle_addstatus</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-addstatus &lt;name&gt; &lt;status&gt; .. add status of name. &quot;&quot;&quot;</span>

    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">)</span> <span class="o">!=</span> <span class="mf">2</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;name&gt; &lt;status&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">name</span><span class="p">,</span> <span class="n">status</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span>
    <span class="n">status</span> <span class="o">=</span> <span class="n">status</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">users</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t find user </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">name</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="k">if</span> <span class="n">users</span><span class="o">.</span><span class="n">gotstatus</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">status</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> already has status </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">status</span><span class="p">))</span>
        <span class="k">return</span>

    <span class="n">result</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">adduserstatus</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">status</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">result</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> status added&#39;</span> <span class="o">%</span> <span class="n">status</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;add failed&#39;</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-addstatus&#39;</span><span class="p">,</span> <span class="n">handle_addstatus</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-addstatus&#39;</span><span class="p">,</span> <span class="s">&#39;user-addstatus &lt;name&gt; &lt;status&gt;&#39;</span><span class="p">,</span> <span class="s">&#39;user-addstatus dunker #dunkbots&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;setstatus&#39;</span><span class="p">,</span> <span class="s">&#39;user-addstatus&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;addstatus&#39;</span><span class="p">,</span> <span class="s">&#39;user-addstatus&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-add mtest9 mekker@test9&#39;).add(&#39;user-addstatus mtest9 mekker&#39;, &#39;MEKKER status added&#39;).add(&#39;delete mtest9&#39;)</span>

<span class="k">def</span> <span class="nf">handle_getstatus</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-getstatus &lt;name&gt; .. get status of name. &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">name</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span>
    <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;name&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">users</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t find user </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">name</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">status</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getuserstatuses</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">status</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;status of </span><span class="si">%s</span><span class="s">: &quot;</span> <span class="o">%</span> <span class="n">name</span><span class="p">,</span> <span class="n">status</span><span class="p">,</span> <span class="n">dot</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> has no status set&#39;</span> <span class="o">%</span> <span class="n">name</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-getstatus&#39;</span><span class="p">,</span> <span class="n">handle_getstatus</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-getstatus&#39;</span><span class="p">,</span> <span class="s">&#39;user-getstatus &lt;name&gt; .. get status of &lt;name&gt;&#39;</span><span class="p">,</span> <span class="s">&#39;user-getstatus dunker&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;getstatus&#39;</span><span class="p">,</span> <span class="s">&#39;user-getstatus&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-add mtest10 mekker@test10&#39;).add(&#39;user-addstatus mtest10 mekker&#39;, &#39;MEKKER status added&#39;).add(&#39;user-getstatus mtest10&#39;, &#39;MEKKER&#39;).add(&#39;delete mtest10&#39;)</span>

<span class="k">def</span> <span class="nf">handle_status</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-status .. get status of user given the command. &quot;&quot;&quot;</span>
    <span class="n">status</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getstatuses</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">userhost</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">status</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;you have status: &quot;</span><span class="p">,</span> <span class="n">status</span><span class="p">,</span> <span class="n">dot</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;you have no status set&#39;</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-status&#39;</span><span class="p">,</span> <span class="n">handle_status</span><span class="p">,</span> <span class="s">&#39;USER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-status&#39;</span><span class="p">,</span> <span class="s">&#39;get status&#39;</span><span class="p">,</span> <span class="s">&#39;user-status&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;status&#39;</span><span class="p">,</span> <span class="s">&#39;user-status&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-status&#39;)</span>

<span class="k">def</span> <span class="nf">handle_delstatus</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-delstatus &lt;name&gt; &lt;status&gt; .. delete status of name. &quot;&quot;&quot;</span>

    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">)</span> <span class="o">!=</span> <span class="mf">2</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;name&gt; &lt;status&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">name</span><span class="p">,</span> <span class="n">status</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span>
    <span class="n">status</span> <span class="o">=</span> <span class="n">status</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">users</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t find user </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">name</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">result</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">deluserstatus</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">status</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">result</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> status deleted&#39;</span> <span class="o">%</span> <span class="n">status</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;</span><span class="si">%s</span><span class="s"> has no </span><span class="si">%s</span><span class="s"> status&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">status</span><span class="p">))</span>
        <span class="k">return</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-delstatus&#39;</span><span class="p">,</span> <span class="n">handle_delstatus</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-delstatus&#39;</span><span class="p">,</span> <span class="s">&#39;user-delstatus &lt;name&gt; &lt;status&gt;&#39;</span><span class="p">,</span> <span class="s">&#39;user-delstatus dunker #dunkbots&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;delstatus&#39;</span><span class="p">,</span> <span class="s">&#39;user-delstatus&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-add mtest11 mekker@test11&#39;).add(&#39;user-addstatus mtest11 mekker&#39;).add(&#39;user-delstatus mtest11 mekker&#39;, &#39;MEKKER status deleted&#39;).add(&#39;delete mtest11&#39;)</span>

<span class="k">def</span> <span class="nf">handle_adduserhost</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-adduserhost &lt;name&gt; &lt;userhost&gt; .. add to userhosts of name. &quot;&quot;&quot;</span> 

    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">)</span> <span class="o">!=</span> <span class="mf">2</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;name&gt; &lt;userhost&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">name</span><span class="p">,</span> <span class="n">userhost</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">users</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t find user </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">name</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="k">if</span> <span class="n">users</span><span class="o">.</span><span class="n">gotuserhost</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">userhost</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> already has userhost </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">userhost</span><span class="p">))</span>
        <span class="k">return</span>

    <span class="n">result</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">adduserhost</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">userhost</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">result</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;userhost added&#39;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;add failed&#39;</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-adduserhost&#39;</span><span class="p">,</span> <span class="n">handle_adduserhost</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-adduserhost&#39;</span><span class="p">,</span> <span class="s">&#39;user-adduserhost &lt;name&gt; &lt;userhost&gt;&#39;</span><span class="p">,</span> <span class="s">&#39;user-adduserhost dunker bart@%.a2000.nl&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;adduserhost&#39;</span><span class="p">,</span> <span class="s">&#39;user-adduserhost&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;adduserhosts&#39;</span><span class="p">,</span> <span class="s">&#39;user-adduserhost&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-add mtest12 mekker@test12&#39;).add(&#39;user-adduserhost mtest12 mekker2@test122&#39;, &#39;userhost added&#39;).add(&#39;delete mtest12&#39;)</span>

<span class="k">def</span> <span class="nf">handle_deluserhost</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-deluserhost &lt;name&gt; &lt;userhost&gt; .. remove from userhosts of name. &quot;&quot;&quot;</span>

    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">)</span> <span class="o">!=</span> <span class="mf">2</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;name&gt; &lt;userhost&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">name</span><span class="p">,</span> <span class="n">userhost</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>

    <span class="k">if</span> <span class="n">bot</span><span class="o">.</span><span class="n">ownercheck</span><span class="p">(</span><span class="n">userhost</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;can delete userhosts from owner&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">users</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t find user </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">name</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">result</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">deluserhost</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">userhost</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">result</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;userhost removed&#39;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;</span><span class="si">%s</span><span class="s"> has no </span><span class="si">%s</span><span class="s"> in userhost list&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> \
<span class="n">userhost</span><span class="p">))</span>
        <span class="k">return</span>  

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-deluserhost&#39;</span><span class="p">,</span> <span class="n">handle_deluserhost</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-deluserhost&#39;</span><span class="p">,</span> <span class="s">&#39;user-deluserhost &lt;name&gt; &lt;userhost&gt; .. delete from usershosts of &lt;name&gt; userhost &lt;userhost&gt;&#39;</span><span class="p">,</span><span class="s">&#39;user-deluserhost dunker bart1@bla.a2000.nl&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;deluserhost&#39;</span><span class="p">,</span> <span class="s">&#39;user-deluserhost&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;deluserhosts&#39;</span><span class="p">,</span> <span class="s">&#39;user-deluserhost&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-add mtest32 mekker@test32&#39;).add(&#39;user-adduserhost mtest12 mekker2@test32&#39;).add(&#39;user-deluserhost mtest12 mekker2@test32&#39;, &#39;userhost removed&#39;).add(&#39;delete mtest32&#39;)</span>

<span class="k">def</span> <span class="nf">handle_getuserhosts</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-getuserhosts &lt;name&gt; .. get userhosts of name. &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">who</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span>
    <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;name&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">who</span> <span class="o">=</span> <span class="n">who</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
    <span class="n">userhosts</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getuserhosts</span><span class="p">(</span><span class="n">who</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">userhosts</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;userhosts of </span><span class="si">%s</span><span class="s">: &quot;</span> <span class="o">%</span> <span class="n">who</span><span class="p">,</span> <span class="n">userhosts</span><span class="p">,</span> <span class="n">dot</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t find user </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">who</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-getuserhosts&#39;</span><span class="p">,</span> <span class="n">handle_getuserhosts</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-getuserhosts&#39;</span><span class="p">,</span> <span class="s">&#39;user-getuserhosts &lt;name&gt; .. get userhosts of &lt;name&gt;&#39;</span><span class="p">,</span> <span class="s">&#39;getuserhosts dunker&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;getuserhosts&#39;</span><span class="p">,</span> <span class="s">&#39;user-getuserhosts&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-add mtest13 mekker@test13&#39;).add(&#39;user-adduserhost mtest13 mekker@test13&#39;).add(&#39;user-getuserhosts mtest13&#39;, &#39;mekker@test13&#39;).add(&#39;delete mtest13&#39;)</span>

<span class="k">def</span> <span class="nf">handle_userhosts</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-userhosts .. get userhosts of user giving the command. &quot;&quot;&quot;</span>

    <span class="n">userhosts</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">gethosts</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">userhost</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">userhosts</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;you have userhosts: &quot;</span><span class="p">,</span> <span class="n">userhosts</span><span class="p">,</span> <span class="n">dot</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-userhosts&#39;</span><span class="p">,</span> <span class="n">handle_userhosts</span><span class="p">,</span> <span class="s">&#39;USER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-userhosts&#39;</span><span class="p">,</span> <span class="s">&#39;get userhosts&#39;</span><span class="p">,</span> <span class="s">&#39;user-userhosts&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;userhosts&#39;</span><span class="p">,</span> <span class="s">&#39;user-userhosts&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-userhosts&#39;)</span>

<span class="k">def</span> <span class="nf">handle_getemail</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-getemail &lt;name&gt; .. get email of name. &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">name</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span>
    <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;name&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">users</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t find user </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">name</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">email</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getuseremail</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">email</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="n">email</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;no email set&#39;</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-getemail&#39;</span><span class="p">,</span> <span class="n">handle_getemail</span><span class="p">,</span> <span class="s">&#39;USER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-getemail&#39;</span><span class="p">,</span> <span class="s">&#39;user-getemail &lt;name&gt; .. get email from user &lt;name&gt;&#39;</span><span class="p">,</span> <span class="s">&#39;user-getemail dunker&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;getemail&#39;</span><span class="p">,</span> <span class="s">&#39;user-getemail&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-add mtest14 mekker@test14&#39;).add(&#39;user-setemail mtest14 mekker@test14&#39;).add(&#39;user-getemail mtest14&#39;, &#39;mekker@test14&#39;).add(&#39;delete mtest14&#39;)</span>

<span class="k">def</span> <span class="nf">handle_setemail</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-setemail &lt;name&gt; .. set email of name. &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">name</span><span class="p">,</span> <span class="n">email</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span>
    <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;name&gt; &lt;email&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">users</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t find user </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">name</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">users</span><span class="o">.</span><span class="n">setemail</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">email</span><span class="p">)</span>
    <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;email set&#39;</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-setemail&#39;</span><span class="p">,</span> <span class="n">handle_setemail</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-setemail&#39;</span><span class="p">,</span> <span class="s">&#39;user-setemail &lt;name&gt; &lt;email&gt;.. set email of user &lt;name&gt;&#39;</span><span class="p">,</span> <span class="s">&#39;user-setemail dunker bart@gozerbot.org&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;setemail&#39;</span><span class="p">,</span> <span class="s">&#39;user-setemail&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-add mtest15 mekker@test15&#39;).add(&#39;user-setemail mtest15 mekker@test15&#39;, &#39;email set&#39;).add(&#39;delete mtest15&#39;)</span>

<span class="k">def</span> <span class="nf">handle_email</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-email .. show email of user giving the command. &quot;&quot;&quot;</span>

    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">)</span> <span class="o">!=</span> <span class="mf">0</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;use getemail to get the email address of an user .. </span><span class="se">\</span>
<span class="s">email shows your own mail address&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">email</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getemail</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">userhost</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">email</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="n">email</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;no email set&#39;</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-email&#39;</span><span class="p">,</span> <span class="n">handle_email</span><span class="p">,</span> <span class="s">&#39;USER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-email&#39;</span><span class="p">,</span> <span class="s">&#39;get email&#39;</span><span class="p">,</span> <span class="s">&#39;user-email&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;email&#39;</span><span class="p">,</span> <span class="s">&#39;user-email&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-setemail mekker@mekker&#39;).add(&#39;user-email&#39;, &#39;mekker@mekker&#39;)</span>

<span class="k">def</span> <span class="nf">handle_delemail</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-delemail .. reset email of user giving the command. &quot;&quot;&quot;</span>

    <span class="n">name</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getname</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">userhost</span><span class="p">)</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">name</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t find user for </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">ievent</span><span class="o">.</span><span class="n">userhost</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">result</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">delallemail</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">result</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;email removed&#39;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;delete failed&#39;</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-delemail&#39;</span><span class="p">,</span> <span class="n">handle_delemail</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-delemail&#39;</span><span class="p">,</span> <span class="s">&#39;reset email&#39;</span><span class="p">,</span> <span class="s">&#39;user-delemail&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;delemail&#39;</span><span class="p">,</span> <span class="s">&#39;user-delemail&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-setemail mekker@email&#39;).add(&#39;user-delemail&#39;, &#39;email removed&#39;)</span>

<span class="k">def</span> <span class="nf">handle_addpermit</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-addpermit &lt;name&gt; &lt;permit&gt; .. add permit to permit list of &lt;name&gt;. &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">who</span><span class="p">,</span> <span class="n">what</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span>
    <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&quot;&lt;name&gt; &lt;permit&gt;&quot;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">users</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">who</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t find username of </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">who</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">name</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getname</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">userhost</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">users</span><span class="o">.</span><span class="n">gotpermit</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="p">(</span><span class="n">who</span><span class="p">,</span> <span class="n">what</span><span class="p">)):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> is already allowed to do </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">who</span><span class="p">,</span> <span class="n">what</span><span class="p">))</span>
        <span class="k">return</span>

    <span class="n">result</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">adduserpermit</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">who</span><span class="p">,</span> <span class="n">what</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">result</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;permit added&#39;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;add failed&#39;</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-addpermit&#39;</span><span class="p">,</span> <span class="n">handle_addpermit</span><span class="p">,</span> <span class="s">&#39;USER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-addpermit&#39;</span><span class="p">,</span> <span class="s">&#39;user-addpermit &lt;nick&gt; &lt;what&gt; .. permit nick access to &lt;what&gt; .. use setperms to add permissions&#39;</span><span class="p">,</span> <span class="s">&#39;user-addpermit dunker todo&#39;</span><span class="p">)</span>
<span class="n">aliasdel</span><span class="p">(</span><span class="s">&#39;allow&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-add mtest16 mekker@test16&#39;).add(&#39;user-addpermit mtest16 todo&#39;, &#39;permit added&#39;).add(&#39;user-delpermit mtest16 todo&#39;).add(&#39;delete mtest16&#39;)</span>

<span class="k">def</span> <span class="nf">handle_permit</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-permit .. get permit list of user giving the command. &quot;&quot;&quot;</span>

    <span class="k">if</span> <span class="n">ievent</span><span class="o">.</span><span class="n">rest</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;use the user-addpermit command to allow somebody </span><span class="se">\</span>
<span class="s">something .. use getname &lt;nick&gt; to get the username of somebody .. this </span><span class="se">\</span>
<span class="s">command shows what permits you have&quot;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">name</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getname</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">userhost</span><span class="p">)</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">name</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t find user for </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">ievent</span><span class="o">.</span><span class="n">userhost</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">permits</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getuserpermits</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">permits</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;you permit the following: &quot;</span><span class="p">,</span> <span class="n">permits</span><span class="p">,</span> <span class="n">dot</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;you don&#39;t have any permits&quot;</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-permit&#39;</span><span class="p">,</span> <span class="n">handle_permit</span><span class="p">,</span> <span class="s">&#39;USER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-permit&#39;</span><span class="p">,</span> <span class="s">&#39;show permit of user giving the command&#39;</span><span class="p">,</span> <span class="s">&#39;user-permit&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;permit&#39;</span><span class="p">,</span> <span class="s">&#39;user-permit&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-add mtest17 mekker@test17&#39;).add(&#39;user-addpermit mtest17 todo&#39;, &#39;permit added&#39;).add(&#39;user-delpermit mtest17 todo&#39;).add(&#39;delete mtest17&#39;)</span>

<span class="k">def</span> <span class="nf">handle_userdelpermit</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-delpermit &lt;name&gt; &lt;permit&gt; .. remove (name, permit) from permit list. &quot;&quot;&quot;</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">who</span><span class="p">,</span> <span class="n">what</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span>
    <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&quot;&lt;name&gt; &lt;what&gt;&quot;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">users</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">who</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t find registered name of </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">who</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">name</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getname</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">userhost</span><span class="p">)</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">users</span><span class="o">.</span><span class="n">gotpermit</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="p">(</span><span class="n">who</span><span class="p">,</span> <span class="n">what</span><span class="p">)):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> is already not allowed to do </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">who</span><span class="p">,</span> <span class="n">what</span><span class="p">))</span>
        <span class="k">return</span>

    <span class="n">result</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">deluserpermit</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="p">(</span><span class="n">who</span><span class="p">,</span> <span class="n">what</span><span class="p">))</span>

    <span class="k">if</span> <span class="n">result</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> denied&#39;</span> <span class="o">%</span> <span class="n">what</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;delete failed&#39;</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-delpermit&#39;</span><span class="p">,</span> <span class="n">handle_userdelpermit</span><span class="p">,</span> <span class="s">&#39;USER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-delpermit&#39;</span><span class="p">,</span> <span class="s">&#39;user-delpermit &lt;name&gt; &lt;permit&gt;&#39;</span><span class="p">,</span> <span class="s">&#39;user-delpermit dunker todo&#39;</span><span class="p">)</span>
<span class="n">aliasdel</span><span class="p">(</span><span class="s">&#39;deny&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-add mtest18 mekker@test17&#39;).add(&#39;user-addpermit mtest18 todo&#39;, &#39;permit added&#39;).add(&#39;user-delpermit mtest18 todo&#39;).add(&#39;delete mtest18&#39;)</span>

<span class="k">def</span> <span class="nf">handle_check</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-check &lt;nick&gt; .. get user data of &lt;nick&gt;. &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">nick</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span>
    <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;nick&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">userhost</span> <span class="o">=</span> <span class="n">getwho</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">nick</span><span class="p">)</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">userhost</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t find userhost of </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">nick</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">name</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getname</span><span class="p">(</span><span class="n">userhost</span><span class="p">)</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">name</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t find user&quot;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">userhosts</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getuserhosts</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
    <span class="n">perms</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getuserperms</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
    <span class="n">email</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getuseremail</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
    <span class="n">permits</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getuserpermits</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
    <span class="n">status</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getuserstatuses</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
    <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;userrecord of </span><span class="si">%s</span><span class="s"> = userhosts: </span><span class="si">%s</span><span class="s"> perms: </span><span class="si">%s</span><span class="s"> email: </span><span class="si">%s</span><span class="s"> permits: </span><span class="si">%s</span><span class="s"> status: </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">userhosts</span><span class="p">),</span> <span class="nb">str</span><span class="p">(</span><span class="n">perms</span><span class="p">),</span> <span class="nb">str</span><span class="p">(</span><span class="n">email</span><span class="p">),</span> <span class="nb">str</span><span class="p">(</span><span class="n">permits</span><span class="p">),</span> <span class="nb">str</span><span class="p">(</span><span class="n">status</span><span class="p">)))</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-check&#39;</span><span class="p">,</span> <span class="n">handle_check</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-check&#39;</span><span class="p">,</span> <span class="s">&#39;user-check &lt;nick&gt;&#39;</span><span class="p">,</span> <span class="s">&#39;user-check dunker&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;check&#39;</span><span class="p">,</span> <span class="s">&#39;user-check&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-add mtest19 mekker@test19&#39;).add(&#39;user-check mtest19&#39;, &#39;mekker@test19&#39;).add(&#39;delete mtest19&#39;)</span>

<span class="k">def</span> <span class="nf">handle_show</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-show &lt;name&gt; .. get data of &lt;name&gt;. &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">name</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span>
    <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;name&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">users</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t find user </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">name</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">userhosts</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">users</span><span class="o">.</span><span class="n">getuserhosts</span><span class="p">(</span><span class="n">name</span><span class="p">))</span>
    <span class="n">perms</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">users</span><span class="o">.</span><span class="n">getuserperms</span><span class="p">(</span><span class="n">name</span><span class="p">))</span>
    <span class="n">email</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">users</span><span class="o">.</span><span class="n">getuseremail</span><span class="p">(</span><span class="n">name</span><span class="p">))</span>
    <span class="n">permits</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">users</span><span class="o">.</span><span class="n">getuserpermits</span><span class="p">(</span><span class="n">name</span><span class="p">))</span>
    <span class="n">status</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">users</span><span class="o">.</span><span class="n">getuserstatuses</span><span class="p">(</span><span class="n">name</span><span class="p">))</span>
    <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;userrecord of </span><span class="si">%s</span><span class="s"> = userhosts: </span><span class="si">%s</span><span class="s"> perms: </span><span class="si">%s</span><span class="s"> email: </span><span class="si">%s</span><span class="s"> permits: </span><span class="si">%s</span><span class="s"> status: </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">userhosts</span><span class="p">,</span> <span class="n">perms</span><span class="p">,</span> <span class="n">email</span><span class="p">,</span> <span class="n">permits</span><span class="p">,</span> <span class="n">status</span><span class="p">))</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-show&#39;</span><span class="p">,</span> <span class="n">handle_show</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-show&#39;</span><span class="p">,</span> <span class="s">&#39;user-show &lt;name&gt; .. show data of &lt;name&gt;&#39;</span><span class="p">,</span> <span class="s">&#39;user-show dunker&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-add mtest20 mekker@test20&#39;).add(&#39;user-show mtest20&#39;, &#39;mekker@test20&#39;).add(&quot;delete mtest20&quot;)</span>

<span class="k">def</span> <span class="nf">handle_match</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-match &lt;userhost&gt; .. get data of &lt;userhost&gt;. &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">userhost</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span>
    <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;userhost&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">name</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getname</span><span class="p">(</span><span class="n">userhost</span><span class="p">)</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">name</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t find user with userhost </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">userhost</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">userhosts</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">users</span><span class="o">.</span><span class="n">gethosts</span><span class="p">(</span><span class="n">userhost</span><span class="p">))</span>
    <span class="n">perms</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">users</span><span class="o">.</span><span class="n">getperms</span><span class="p">(</span><span class="n">userhost</span><span class="p">))</span>
    <span class="n">email</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">users</span><span class="o">.</span><span class="n">getemail</span><span class="p">(</span><span class="n">userhost</span><span class="p">))</span>
    <span class="n">permits</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">users</span><span class="o">.</span><span class="n">getpermits</span><span class="p">(</span><span class="n">userhost</span><span class="p">))</span>
    <span class="n">status</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">users</span><span class="o">.</span><span class="n">getstatuses</span><span class="p">(</span><span class="n">userhost</span><span class="p">))</span>

    <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;userrecord of </span><span class="si">%s</span><span class="s"> = userhosts: </span><span class="si">%s</span><span class="s"> perms: </span><span class="si">%s</span><span class="s"> email: </span><span class="si">%s</span><span class="s"> permits: </span><span class="si">%s</span><span class="s"> status: </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">userhosts</span><span class="p">,</span> <span class="n">perms</span><span class="p">,</span> <span class="n">email</span><span class="p">,</span> <span class="n">permits</span><span class="p">,</span> <span class="n">status</span><span class="p">))</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-match&#39;</span><span class="p">,</span> <span class="n">handle_match</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;USER&#39;</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">])</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-match&#39;</span><span class="p">,</span> <span class="s">&#39;user-match &lt;userhost&gt;&#39;</span><span class="p">,</span> <span class="s">&#39;user-match test@test&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;match&#39;</span><span class="p">,</span> <span class="s">&#39;user-match&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-add mtest21 mekker@test21&#39;).add(&#39;user-match mekker@test21&#39;, &#39;mekker@test21&#39;).add(&quot;delete mtest21&quot;)</span>

<span class="k">def</span> <span class="nf">handle_getuserstatus</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-allstatus &lt;status&gt; .. list users with status &lt;status&gt;. &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">status</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>
    <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;status&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">result</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getstatususers</span><span class="p">(</span><span class="n">status</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">result</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;users with </span><span class="si">%s</span><span class="s"> status: &quot;</span> <span class="o">%</span> <span class="n">status</span><span class="p">,</span> <span class="n">result</span><span class="p">,</span> <span class="n">dot</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;no users with </span><span class="si">%s</span><span class="s"> status found&quot;</span> <span class="o">%</span> <span class="n">status</span><span class="p">)</span>
    <span class="k">return</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-allstatus&#39;</span><span class="p">,</span> <span class="n">handle_getuserstatus</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-allstatus&#39;</span><span class="p">,</span> <span class="s">&#39;user-allstatus &lt;status&gt; .. get all users with &lt;status&gt; status&#39;</span><span class="p">,</span> <span class="s">&#39;user-allstatus #dunkbots&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-allstatus&#39;)</span>

<span class="k">def</span> <span class="nf">handle_getuserperm</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-allperm &lt;perm&gt; .. list users with permission &lt;perm&gt;. &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">perm</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>
    <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;perm&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">result</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getpermusers</span><span class="p">(</span><span class="n">perm</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">result</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;users with </span><span class="si">%s</span><span class="s"> permission: &#39;</span> <span class="o">%</span> <span class="n">perm</span><span class="p">,</span> <span class="n">result</span><span class="p">,</span> <span class="n">dot</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;no users with </span><span class="si">%s</span><span class="s"> permission found&quot;</span> <span class="o">%</span> <span class="n">perm</span><span class="p">)</span>
    <span class="k">return</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-allperm&#39;</span><span class="p">,</span> <span class="n">handle_getuserperm</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-allperm&#39;</span><span class="p">,</span> <span class="s">&#39;user-allperm &lt;perm&gt; .. get users with &lt;perm&gt; permission&#39;</span><span class="p">,</span> <span class="s">&#39;user-allperm rss&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-allperm OPER&#39;, &#39;owner&#39;)</span>

<span class="k">def</span> <span class="nf">handle_usersearch</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; search for user matching given userhost. &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">what</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span>
    <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;what&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">result</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">usersearch</span><span class="p">(</span><span class="n">what</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">result</span><span class="p">:</span>
        <span class="n">res</span> <span class="o">=</span> <span class="p">[</span><span class="s">&quot;(</span><span class="si">%s</span><span class="s">) </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">u</span> <span class="k">for</span> <span class="n">u</span> <span class="ow">in</span> <span class="n">result</span><span class="p">]</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;users matching </span><span class="si">%s</span><span class="s">: &#39;</span> <span class="o">%</span> <span class="n">what</span><span class="p">,</span> <span class="n">res</span><span class="p">,</span> <span class="n">dot</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;no userhost matching </span><span class="si">%s</span><span class="s"> found&#39;</span> <span class="o">%</span> <span class="n">what</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-search&#39;</span><span class="p">,</span> <span class="n">handle_usersearch</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;user-search&#39;</span><span class="p">,</span> <span class="s">&#39;search users userhosts&#39;</span><span class="p">,</span> <span class="s">&#39;user-search gozerbot&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;user-search exe&#39;, &#39;exec&#39;)</span>

<span class="k">def</span> <span class="nf">handle_addpermall</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-addpermall &lt;perm&gt; .. add permission to all users. &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">perm</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>
    <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;perm&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="k">if</span> <span class="n">perm</span> <span class="o">==</span> <span class="s">&#39;OPER&#39;</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t add OPER permissions to all&quot;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">users</span><span class="o">.</span><span class="n">addpermall</span><span class="p">(</span><span class="n">perm</span><span class="p">)</span>
    <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> perm added&#39;</span> <span class="o">%</span> <span class="n">perm</span><span class="p">)</span>

<span class="c">#cmnds.add(&#39;user-addpermall&#39;, handle_addpermall, &#39;OPER&#39;)</span>
<span class="c">#examples.add(&#39;user-addpermall&#39;, &#39;user-addpermall &lt;perm&gt; .. add &lt;permission&gt; to all users&#39;, &#39;addpermsall USER&#39;)</span>
<span class="c">#tests.add(&#39;user-addpermall blabla&#39;, &#39;BLABLA perm added&#39;).add(&#39;user-delpermall blabla&#39;)</span>

<span class="k">def</span> <span class="nf">handle_delpermall</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; user-delpermall &lt;perm&gt; .. delete permission from all users. &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">perm</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>
    <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;perm&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="k">if</span> <span class="n">perm</span> <span class="o">==</span> <span class="s">&#39;OPER&#39;</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t delete OPER permissions from all&quot;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">users</span><span class="o">.</span><span class="n">delpermall</span><span class="p">(</span><span class="n">perm</span><span class="p">)</span>
    <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> perm deleted&#39;</span> <span class="o">%</span> <span class="n">perm</span><span class="p">)</span>

<span class="c">#cmnds.add(&#39;user-delpermall&#39;, handle_delpermall, &#39;OPER&#39;)</span>
<span class="c">#examples.add(&#39;user-delpermall&#39;, &#39;user-delpermall &lt;perm&gt; .. delete &lt;permission&gt; from all users&#39;, &#39;delpermsall BLA&#39;)</span>
<span class="c">#tests.add(&#39;user-addpermall blabla&#39;).add(&#39;user-delpermall blabla&#39;, &#39;BLABLA perm deleted&#39;)</span>
</pre></div>
</td></tr></table></div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="../../index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">gozerlib.plugs.user</a><ul>
<li><a class="reference external" href="#code">code</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="uniq.html"
                                  title="previous chapter">gozerlib.plugs.uniq</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="userstate.html"
                                  title="next chapter">gozerlib.plugs.userstate</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../../_sources/gozerlib/plugs/user.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="../../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="userstate.html" title="gozerlib.plugs.userstate"
             >next</a> |</li>
        <li class="right" >
          <a href="uniq.html" title="gozerlib.plugs.uniq"
             >previous</a> |</li>
        <li><a href="../../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2009, Bart Thate.
      Last updated on Nov 14, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.3.
    </div>
  </body>
</html>